---@class SkillEffect453102:BaseSkillEffect
SkillEffect453102 = ClientFight.CreateClass("SkillEffect453102",ClientFight.BaseSkillEffect)
local t = SkillEffect453102
t.SkillEffect453101_trigger_num = "SkillEffect453101_trigger_num"
---@param skill FightUsingSkill
function t:finishSkill(skill,breakin)
    if (breakin) then
        return false;
    end
    local hasTriggerNum = tonumber(skill.parameters[t.SkillEffect453101_trigger_num]) or 0
    local numLimit = skill.skill.skillBean.f_SkillScriptParameter[1]
    if (hasTriggerNum >= numLimit) then
        return false;
    end
    local delay = skill.skill.skillBean.f_SkillScriptParameter[3]
    EventManager.addDelayedEvent(skill.fight,skill.fight.frame + delay/ Global.FIGHT_FRAME,function()
        skill.flyBegin = skill.target
        SkillManager.triggerSkill(skill,nil,skill.skill.skillBean.f_SkillID);
    end)

    return false;
end
---@param parentSkill FightUsingSkill
---@param target Fighter
---@param triggerSkill FightUsingSkill
---@return SkillEffectResult
function t:triggerSkill(parentSkill,target,triggerSkill)
    triggerSkill.flyBegin = parentSkill.flyBegin
    local hasTriggerNum = tonumber(parentSkill.parameters[t.SkillEffect453101_trigger_num]) or 0
    triggerSkill.parameters[t.SkillEffect453101_trigger_num] = hasTriggerNum+1--//弹弹乐次数+1

    local fight = parentSkill.fight
    local fighter = parentSkill.fighter
    local triggerSkillBean = triggerSkill.skill.skillBean
    -- 整个技能不可重复目标
    local team = fight.teams[3 - fighter.teamIndex];
    local fighters = team.fighters;
    local targetLists = {}
    local dis = Utils.toRatio(triggerSkill.skill.skillBean.f_SkillScriptParameter[2])
    for k,next in pairs(fighters) do
        self:FighterLoop(next,parentSkill,triggerSkillBean,dis,targetLists)
    end
    target = targetLists[math.random(#targetLists)]
    if target == nil then
        return SkillEffectResult.New(true,false);
    end
    triggerSkill.target = target

    -- 整个技能不可重复目标
    if (triggerSkillBean.f_SkillPointRepeat == SkillPointRepeatEnum.UNREPEATABLE_ALL) then
        triggerSkill.excludes = parentSkill.excludes
    end

    -- 目标不可重复
    if (triggerSkillBean.f_SkillPointRepeat ~= SkillPointRepeatEnum.REPEATABLE) then
        parentSkill.excludes[target.fighterId] = true;
    end

    -- 如果非分离技能，打断所有正在使用的非分离技能
    if (triggerSkillBean.f_SkillOut ~= 1 and parentSkill.fighter.getUsingSkill ~= nil) then
        SkillManager.finishSkill(parentSkill.fighter.usingSkill, true, FinishSkillReasonEnum.OTHER);
    end
    if (triggerSkillBean.f_SkillOut == 1) then
        local frameInfo =ReportManager.flyToJsonString(fight, parentSkill.flyBegin, target,
                triggerSkill)
        table.insert(fight.actions, frameInfo);
        FightManager.playActions(frameInfo,triggerSkill)
    else
        triggerSkill.originalTargetPlacePosition = Vector2(target.position.x,target.position.y)
        local attack = ReportManager.attackToJsonString(fight, parentSkill.fighter, target, triggerSkill, triggerSkill.speed);
        table.insert(fight.actions,attack)
        FightManager.playActions(attack)
        if (triggerSkillBean.f_Speed ~= 0 or triggerSkillBean.f_moveFrame ~= 0) then
            fighter.moveAttackAction = attack
        end
    end
    SkillManager.addSkill(fight, triggerSkill);
    local logTarget = target;
    SkillRoleMgr.savePathFile( "[" .. fight.frame .. "][SKILL]" .. parentSkill.fighter.fighterId .. "对"
    .. logTarget.fighterId .. "触发技能" .. triggerSkillBean.f_SkillID);

    -- 开始释放技能
    SkillManager.prepareSkill(triggerSkill, parentSkill.position);

    -- 子技能加速
    if (parentSkill.frame < parentSkill.skipFrame) then
        triggerSkill.skipFrame = parentSkill.skipFrame - parentSkill.frame
    end
    -- 聚光灯播放效果
    if (triggerSkill.stage ~= FightSkillStageEnum.FINISH
    and triggerSkill.frame < triggerSkill.skipFrame) then
        fight:addFrozenSkills(triggerSkill);
    end
    return SkillEffectResult.New(true,true);
end
---@param next Fighter
---@param parentSkill FightUsingSkill
---@param triggerSkillBean T_skillBean
function t:FighterLoop(next,parentSkill,triggerSkillBean,dis,targetLists)
    if (next == parentSkill.target) then
        return
    end
    if (next.summons and not next:isRealSummons()) then
        return
    end
    if (FighterStateEnum.is(next, FighterStateEnum.CAN_NOT_SELECT_BY_ENEMY)) then
        return
    end
    -- 移除死亡
    if (next:isDie()) then
        return
    end
    -- 移除召唤物
    if (triggerSkillBean.f_AimTarget == 1 and next.summons) then
        return
    end
    -- 移除英雄
    if (triggerSkillBean.f_AimTarget == 2 and not next.summons) then
        return
    end
    if (triggerSkillBean.f_AimTarget == 3) then
        if (next.summons and next.heroBean.f_Type==3) then
            return
        end
    end
    local distance = DistanceUtil.countDistance(next.position, parentSkill.target.position);
    if (distance > dis) then
        return
    end
    table.insert(targetLists,next)
end
t.New()